package fr.contacts.controllers;

import java.util.List;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import fr.contacts.models.Contact;


@Controller
public class SearchController {
	
	
	@RequestMapping ( value = "/contact/search")
	public String searchContact(@RequestParam(required=false, value="critereExact") Boolean critereExact,
								@RequestParam("searchField") String critere,
								@RequestParam("searchValue") String keyword,
								Model model) {
		System.out.println("Passing through Search");
		if(critereExact == null) critereExact=false;

		List<Contact> searchResultList = ContactsDAO.searchContact(critereExact, critere, keyword);
		model.addAttribute("contactList", searchResultList);
		
		return "/WEB-INF/views/searchresult.jsp";
	}
	
	@RequestMapping ( value = "/contact/searchform")
	public String searchContact(Model model) {
		System.out.println("Passing through Form");
		return "/WEB-INF/views/search.jsp";
	}
	

}
